package cn.com.dwr.service.impl;

import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.com.dwr.entity.AppSpecificationValue;
import cn.com.dwr.service.AppSpecificationValueService;
import cn.com.dwr.mapper.AppSpecificationValueMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 邓文润
* @description 针对表【app_specification_value】的数据库操作Service实现
* @createDate 2023-12-12 07:13:55
*/
@Service
public class AppSpecificationValueServiceImpl extends ServiceImpl<AppSpecificationValueMapper, AppSpecificationValue>
    implements AppSpecificationValueService{

    @Override
    public List<AppSpecificationValue> listByProductId(Long productId) {

        // 多种规格
        List<AppSpecificationValue> specificationValues = this.list(new QueryWrapper<AppSpecificationValue>()
                .eq("product_Id", productId));
        if(specificationValues == null || specificationValues.size() == 0){
            // 单规格商品
            specificationValues = getSingleSpec();
        }
        return specificationValues;
    }

    private List<AppSpecificationValue> getSingleSpec() {

        AppSpecificationValue value = new AppSpecificationValue();
        value.setSpec("规格");
        value.setValue("默认规格");
        return ListUtil.toList(value);
    }
}




